/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package entreprise;

import java.util.ArrayList;
import java.util.Date;
import mapping.DBSession;
import mapping.DBSessionDrug;
import mapping.DBSessionService;

/**
 *
 * @author Quoc-Khai
 */
public class SessionService {
    DBSessionDrug dBSessionDrug;
    DBSessionService dBSessionService;
    DBSession dBSession;
    public Session getSession(String sessionID){
        dBSession=new DBSession();
        Session session=dBSession.getSession(sessionID);
        return session;
    }
    
    public boolean createSession(String sessionID, Date sessionDate, String doctor, String require, String diagnostic,String patientID){
        dBSession = new DBSession();
        Session iSession = new Session();
        iSession.setSessionDate(sessionDate);
        iSession.setDoctor(doctor);
        iSession.setRequire(require);
        iSession.setDiagnostic(diagnostic);
        iSession.setPatientID(patientID);
        if(dBSession.createSession(iSession)){
            return true;
        }else{
            return false;
        }
    }
    public boolean deleteSession(String sessionID){
        dBSession = new DBSession();
        Session iSession = dBSession.getSession(sessionID);
        if (iSession!=null) {
            dBSession.deleteSession(sessionID);
            return true;
        }        
//        System.out.println("Session not existe!");
        return false;
    }
    public boolean updateSession(String sessionID, Date sessionDate, String doctor, String require, String diagnostic,String patientID){
        dBSession = new DBSession();
        Session iSession = dBSession.getSession(sessionID);
        if (iSession!=null) {
            iSession.setSessionID(sessionID);
            iSession.setSessionDate(sessionDate);
            iSession.setDoctor(doctor);
            iSession.setRequire(require);
            iSession.setDiagnostic(diagnostic);
            iSession.setPatientID(patientID);
            dBSession.updateSession(iSession);
            return true;
        }
//        System.out.println("Session not existe!");
        return false;
    }
    public ArrayList<Session> sessions(String patientID){
        dBSession=new DBSession();
        ArrayList<Session> sessions=dBSession.getSessions(patientID);        
        return sessions;
    }

    public int getLatestSessionID() {
        dBSession=new DBSession();
        return dBSession.getLatestSessionID();
    }
    
    public boolean createSessionDrug(int sessionID, String[] drugIDs){
        dBSessionDrug=new DBSessionDrug();
        return dBSessionDrug.createSessionDrug(sessionID, drugIDs);
    } 
    public ArrayList<Drug> getDrugsOfSession(int sessionID){
        dBSessionDrug=new DBSessionDrug();        
        return dBSessionDrug.getDrugs(sessionID);
    }

    public boolean createSessionService(int sessionID, String[] servicesIDs) {
        dBSessionService=new DBSessionService();
        return dBSessionService.createSessionService(sessionID,servicesIDs);
    }
    
    public ArrayList<Service> getServicesOfSession(int sessionID){
        dBSessionService=new DBSessionService();
        return dBSessionService.getServices(sessionID);
    }
}
